

#include "SysClock.h"
#include "App.h"
#include "outp_drv.h"
#include "hardware.h"

#define   APP_START		0
#define   APP_MAIN		1
#define   APP_FINISH		2


static unsigned char app_state = APP_START;

#define   TIME_15_MIN		900


typedef struct
{
	unsigned int time;
	unsigned int outputs;
}time_point_t;

#if 0
const time_point_t table [] =
{
	{0,   0b0000000000000001},
	{30,  0b0000000000001011},
	{120, 0b0000000000010011},
	{210, 0b0000000000100011},
	{300, 0b0000000001000011},
	{390, 0b0000000010000011},
	{480, 0b0000000100000011},
	{570, 0b0000001000000011},
	{660, 0b0000010000000011},
	{750, 0b0000100000000011},
	{840, 0b0001000000000011},
	{930, 0b0010000000000011},
	
	{1020,0b0000000000000000},
	
	{2020,0b0000000000001011},
	{2110,0b0000000000010011},
	{2200,0b0000000000100011},
	{2290,0b0000000001000011},
	{2380,0b0000000010000011},
	{2470,0b0000000100000011},
	{2560,0b0000001000000011},
	{2650,0b0000010000000011},
	{2740,0b0000100000000011},
	{2830,0b0001000000000011},
	{2920,0b0010000000000011},
	{3010,0b0000000000000111},
	
	{3030,0b0000000000000000}
};
#endif


const time_point_t table [] =
{
	{0,   0b0000000000000001},
	{10,  0b0000000000000011},
	{100, 0b0000000000000101},
	{190, 0b0000000000001001},
	{280, 0b0000000000010001},
	{370, 0b0000000000100001},
	{460, 0b0000000001000001},
	{550, 0b0000000010000001},
	{640, 0b0000000100000001},
	{730, 0b0000001000000001},
	{810, 0b0000010000000001},
	{900, 0b0000100000000001},
	{990, 0b0001000000000001},
	{1080,0b0010000000000001},
	{1100,0b0000000000000000}
};


unsigned int tcnt;
unsigned char step;

void app_c15 ( void );

void app_c15 ( void )
{

	if ( app_state != APP_FINISH && SYS_CLOCK_500ms )
	{
		LED ^= 1;
	}


	if ( (!TEST_BTN && SYS_CLOCK_100ms) || (TEST_BTN && SYS_CLOCK_1000ms) )
	{
		tcnt++;
	}

	switch( app_state )
	{
		case APP_START:
			app_state = APP_MAIN;
			tcnt = 0;
			step = 0;
			
		case APP_MAIN:
			if ( table[step].time == tcnt )
			{
				Out_Status = table[step].outputs;
				if ( ++step >= (sizeof(table)/sizeof(time_point_t)) )
				{ 
					app_state = APP_FINISH;
				}
			}
			break;
			
		case APP_FINISH:
			LED = 0;
			break;
	}  
}
